<?php

class controller_config extends controller_theme
{
	public function __construct()
	{
		parent::__construct();
	}
	

	public function config_system()
	{
		$config = bone::get_config('system');

		$template = bone::get_template('config.config_system', APP_DIR);
		$template->set_title('配置系统参数');
		$template->set('config', $config);
		$template->set_data($this->get_data());
		$template->display();
	}

	public function config_system_save()
	{
		$config = bone::get_config('system');
		$config->offline = post('offline', '0');
		$config->offline_message = post('offline_message', '');
		$config->site_url = post('site_url', '');
		$config->site_name = post('site_name', '');
		$config->sef = post('sef', '0');

		$model = bone::get_model('config', APP_DIR);
		$model->save($config, 'system');

		$this->redirect('./?controller=config&task=config_system', '保存成功');
	}


	public function config_mail()
	{
		$config = bone::get_config('mail');

		$template = bone::get_template('config.config_mail', APP_DIR);
		$template->set_title('配置邮件参数');
		$template->set('config', $config);
		$template->set_data($this->get_data());
		$template->display();
	}

	public function config_mail_save()
	{
		$config = bone::get_config('mail');

		$config->from_mail = post('from_mail', '');
		$config->from_name = post('from_name', '');
		$config->smtp = post('smtp', '0');
		$config->smtp_host = post('smtp_host', '');
		$config->smtp_port = post('smtp_port', 25, 'int');
		$config->smtp_user = post('smtp_user', '');
		$config->smtp_pass = post('smtp_pass', '');

		$model = bone::get_model('config', APP_DIR);
		$model->save($config, 'mail');

		$this->redirect('./?controller=config&task=config_mail', '保存成功');
	}

	public function config_mail_test()
	{
		$template = bone::get_template('config.config_mail_test', APP_DIR);
		$template->set_title('发送邮件测试');
		$template->set_data($this->get_data());
		$template->display();
	}

	public function config_mail_test_save()
	{
		$to_email = post('to_email', '');
		$subject = post('subject', '');
		$body = post('body', '');

		$mail = bone::get('mail');
		$mail->set_subject($subject);
		$mail->set_body($body);
		$mail->to($to_email);


		if( $mail->send() )
			$this->redirect('./?controller=config&task=config_mail_test&to_email='.$to_email, '发送邮件成功');
		else
			$this->redirect('./?controller=config&task=config_mail_test&to_email='.$to_email, '发送邮件失败: '.$mail->get_error(), 'error');
	}

}
?>